import axios from 'axios';
import {getToken} from "@/utils/auth";

// 创建axios实例
const service = axios.create({
    baseURL: 'http://localhost:8080',
    timeout: 30000
});

// 文件上传专用请求方法
export const uploadFile = (config) => {
    const token = getToken();//新增token
    return service({
        method: 'post',
        ...config,
        // 自动处理FormData的Content-Type
        headers: {
            ...config.headers,
            // 不要在这里设置Content-Type!
            ...(token ?{'Authorization': 'Bearer' + token} : {}) //注意没有加上空格
        }
    });
};

export const fileViewPath = 'http://localhost:8080/img/upload/';